import XTextInfo from '@/components/assetsManage/Info'

export default {
  data() {
    return {
      open: false,
      totalAssert: '0.00',
      tradeTotal: '0.00', //交易金额
      tradedNum: '0.00', //交易中金额
      tradingNum: '0.00', //结算中金额
      depositText: '未开通',
      isSetPayPsd: false,
      total: 0
    }
  },
  mounted() {
    this.getAssets()
    this.IsExistPayPwd()
    this.getBankCardList()
    // this.toTixianPage()
    console.log(this.$store.state)
  },

  methods: {
    handle() {
      this.open = !this.open
    },
    //是否设置支付密码
    async IsExistPayPwd() {
      try {
        const res = await this.$api.user.IsExistPayPwd()
        console.log(res)
        this.isSetPayPsd = res.data
      } catch (e) {
        console.log(e)
        //TODO handle the exception
      }
    },
    getList(i) {
      console.log(i)
      uni.navigateTo({
        url: '../trading/trading?type=' + i,
      })
    },
    //获取资产情况
    getAssets() {

      this.$api.user
        .getAssets({
          storeid: this.$store.state.userInfoDetail.store.storeId,
        })
        .then(res => {
          console.log(res)
          // this.totalAssert = parseFloat(res.data.list[0].store_balance)+ parseFloat(res.data.list[0].deposit_balance)
          this.totalAssert =
						Math.floor(
						  (new Number(res.data.store_balance) +
								new Number(res.data.deposit_balance)) *
							100
						) / 100
          console.log(this.totalAssert)
          this.tradingNum = res.data.in_trading || '0.00'
          this.tradedNum = res.data.in_settlement || '0.00'
          this.tradeTotal =
						Math.floor(
						  (new Number(this.tradingNum) + new Number(this.tradedNum)) * 100
						) / 100 || '0.00'
          if (res.data.deposit_balance > 0) {
            this.depositText = '已开通'
          }
        })
        .catch(e => {
          console.log(e)
        })
    },

    toAssetsDetail() {
      uni.navigateTo({
        url: '/pages_common/pages_me/assets/assetsDetail/assetsDetail',
      })
    },
    //保证金
    toMarginPage() {
      uni.navigateTo({
        url: '/pages_common/pages_me/margin/margin',
      })
    },

    toTixianPage() {

      if (this.isSetPayPsd) {
        if (this.totalAssert) {
          this.$api.bindbank.GetCertificationProgress({
            type: 1
          }).then(res => {
          if(res.data.authentication){
          	if (res.data.audit === 3 ) {
          	  if (res.data.bindPhone) {
          	    if (res.data.contractNo) {
          	      uni.navigateTo({
          	        url: '/pages_common/pages_me/assets/cash/cash?total=' + this
          	          .totalAssert
          	      })
          	    } else {
          	      uni.navigateTo({
          	        url: '/pages_common/pages_me/assets/agreement/agreement'
          	      })
          	    }
          	  } else {
          	    uni.navigateTo({
          	      url: '/pages_common/pages_me/assets/bindPhone/bindPhone'
          	    })
          	  }
          	
          	} else {
          	  uni.navigateTo({
          	    url: '/pages_common/pages_me/assets/auditResult/auditResult',
          	  })
          	}
          }else{
          	uni.navigateTo({
          	  url: '/pages_common/pages_me/assets/bankCardManagement/bankCardManagement',
          	})
          }

          })
          // uni.showToast({
          //   title: '敬请期待',
          //   icon: 'none',
          // })
        } else {
          uni.showToast({
            title: '当前无可提现金额',
            icon: 'none',
          })
        }
      } else {
        uni.showToast({
          title: '请先设置支付密码',
          icon: 'none'
        })
        setTimeout(() => {
          uni.navigateTo({
            url: '/pages_common/pages_me/assets/setPassword/setPsd'
          })
        }, 1200)
      }
    },
    // 获取是否绑定银行卡
    getBankCardList() {
      this.$api.user
        .getBankCardList({
          pageIndex: 1,
          pageSize: 100,
        })
        .then(res => {
          if (res.data.total !== 0) {
            // this.list = res.data.list
            this.total = res.data.total
          }
        })
        .catch(e => {
          console.log(e)
        })
    },
    //跳转银行卡
    banCard() {
      this.$api.bindbank.GetCertificationProgress({
        type: 1
      }).then(res => {
				if(res.data.authentication){
					if (res.data.audit === 3 ) {
					  if (res.data.bindPhone) {
					    if (res.data.contractNo) {
					      uni.navigateTo({
					        url: '/pages_common/pages_me/assets/cash/cash?total=' + this
					          .totalAssert
					      })
					    } else {
					      uni.navigateTo({
					        url: '/pages_common/pages_me/assets/agreement/agreement'
					      })
					    }
					  } else {
					    uni.navigateTo({
					      url: '/pages_common/pages_me/assets/bindPhone/bindPhone'
					    })
					  }
					
					} else {
					  uni.navigateTo({
					    url: '/pages_common/pages_me/assets/auditResult/auditResult',
					  })
					}
				}else{
					uni.navigateTo({
					  url: '/pages_common/pages_me/assets/bankCardManagement/bankCardManagement',
					})
				}
      
        // if (res.data.audit === 3 && res.data.authentication) {
        //   uni.navigateTo({
        //     url: '/pages_common/pages_me/assets/bindPhone/bindPhone'
        //   })
        // } else {
        //   uni.navigateTo({
        //     url: '/pages_common/pages_me/assets/bankCardManagement/bankCardManagement',
        //   })
        // }

        // console.log(res)
      })

    },

    dealNmuber(str1, str2) {
      const num1 = new Number(str1).toFixed(2)
      const num2 = new Number(str2).toFixed(2)
      return num1 + num1
    },
  },
  components: {
    XTextInfo,
  },
}
